<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<title>用户详情</title>
		<link rel="stylesheet" href="bower_components/layer/layer.css" />
		<script type="text/javascript" src="bower_components/jquery/dist/jquery.min.js" ></script>
		<script type="text/javascript" src="bower_components/layer/layer.js"></script>
		
	</head>
	<style>
		.layui-layer-title{
			background-color: #3c8dbc;
			color: white;
		}
		.bg_box{
			width: 600px;
			overflow: hidden;
		}
		.header input{
			width: 100%;
		}
		.header{
			width: 600px;
		}
		
		.header tr{
			height: 50px;
			border: solid 1px #cccccc;
		
			}
		
		.data input{
			border:none;
			background: none;
			position: relative;
			left: -100px;
			text-align: left;
			}
		
		.header .label{
			line-height: 50px;
			display: inline-block;
			width: 150px!important;
			text-align: center;
			border-right: 1px solid #CCCCCC ;
		} 
		.header select{
			width: 100%;
		}
		.item_form{
			margin-left:0%!important ;
			margin-top: 30px;
			margin-bottom: 30px;
		}
		.creat_sub{
			width: 150px;
			height: 38px;
			border: none;
			background: #85BFEB;
			color: white;
			margin-top: 40px;
		}
		.creat_num td,th{
			width:100px;
			border: solid 1px #cccccc;
			text-align: center;
		}
		.item_pepo{
			position: relative;
			left: -100px;
			border: none;
			background: none;
			text-align: left;
		}
		.increase{
			width: 80px!important;
			background: none;
			height: 35px;
			border:solid 1px black;
			border-radius: 3px 3px;
		}
		.data input {
			position: relative;
			
		}
		.delect{
			cursor: pointer;
			background: none;
			border: none;
		}
		.layui-input-inline{
			width: 100%;
		}
	</style>

<body>		
		<div class="bg_box">
			
			
			<div class="header">
			
				<form class="item_form" style="height: 40px;text-align: left;">
					<label style="margin-left: 70px;">品名：</label>
					<select style="width: 260px;height: 35px;margin-left: 70px;">
						<option></option>
					</select>
					<input class="increase" type="button" style="margin-left:20px;" value="新增"/>
				</form>
				<table class="header data2">
					<tbody  class="user_basic creat_num">
						<tr>
							<th>品名</th>
							<th>条码</th>
							<th>规格</th>
							<th>色号</th>
							<th>操作</th>
						</tr>
						
						
					</tbody>
			</table>
			</div>
		<div style="width: 100%;text-align: center;">
			<input class="creat_sub" type="button" value="提交"/>
		</div>	
		
	
	</body>

</html>
<script>
			function GetQueryString(name)
{
     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
     var r = window.location.search.substr(1).match(reg);
     if(r!=null)return  unescape(r[2]); return null;
}
var data_id = GetQueryString('id_data');
	$(document).ready(function(){
		var item_ID=[];
		$.ajax({
			type:"get",
			url:"http://www.duoweish.com/apis/ProjectProductInfo/",
			data:{
				Id:data_id,
				},
			success:function(data){
				for (var j = 0; j<data[1].length;j++) {
					var OPtion = '<option>'+data[1][j]+'</option>'
					$("select").append(OPtion);
				}				
				for (var j = 0; j<data[0].length;j++) {
					var New_item = '<tr  pro_id="'+data[0][j][4]+'"><td>'+data[0][j][0]+'</td><td>'+data[0][j][1]+'</td><td>'+data[0][j][2]+'</td><td>'+data[0][j][3]+'</td><td><input class="delect" type="button" value="删除"/></td></tr>'
					$(".creat_num").append(New_item);
					$(".delect").click(function(){
						$(this).parents("tr").remove();
					})
				}
				
			
			}
		});		
	  $(".increase").click(function(){
	  				layer.open({
								        type: 2
								        ,title: "新增产品"
								        ,closeBtn: 1
								        ,area:['380px','480px']
								        ,shade: 0.8
								        ,id: 'LAY_layuipro' 
								       ,shadeClose:true
								        ,btnAlign: 'c'
								        ,moveType: 1 
								        ,content:'http://www.duoweish.com/crm/new_product.html'
									    ,success: function(){
									    	
						          }
					    			  
							})
	  })
	  		$("select").on('change',function(){
	  		
			var Increa_Name = $(this).find("option:selected").text();
			
			$.ajax({
				type:"get",
				url:"http://www.duoweish.com/apis/GetProductInfo/",
				async:true,
				data:{
					Name:Increa_Name
				},
				success:function(data){
					
					
					var New_item = '<tr pro_id="'+data[4]+'"><td>'+data[0]+'</td><td>'+data[1]+'</td><td>'+data[2]+'</td><td>'+data[3]+'</td><td><input class="delect" type="button" value="删除"/></td></tr>'
					$(".creat_num").append(New_item);
					$(".delect").click(function(){
							$(this).parent().parent().remove();
					})
		
				}
			});
	})
		$(".creat_sub").click(function(){
			item_ID=[];
			for (var i = 1;i<$(".data2").find("tr").length;i++) {
				
				item_ID.push($(".data2").find("tr").eq(i).attr('pro_id'));
			}
			if(item_ID==''){
				alert('请选择品名')
			}else{
						$.ajax({
						type:"get",
						url:"http://www.duoweish.com/apis/ProjectProductSubmit/",
						async:true,
						data:{
							Project:data_id,
							Product:item_ID.join('*@*')
						
						},
						success:function(){
							layer.msg("提交成功");
							item_ID=[];
						}
						
					});
				}
			
		
		})
	
		
		
		
		
	})
</script>
